package cn.topkinson.lagou.s3m4.email.service;

import cn.topkinson.base.api.email.EmailRemoteClient;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @Author huangzihao
 * @Date 2020/9/9 20:14
 */
@Service
public class EmailService implements EmailRemoteClient {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public Boolean email(String email, String code) {
        try{
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            //邮件发送人
            simpleMailMessage.setFrom("kinsonosnik@163.com");
            //邮件接收人
            simpleMailMessage.setTo(email);
            //邮件主题
            simpleMailMessage.setSubject("验证码");
            //邮件内容
            simpleMailMessage.setText(code);
            javaMailSender.send(simpleMailMessage);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
